from appium.webdriver.common.mobileby import MobileBy

from lagou.appium_exercise4.pages.add_member_page import AddMemberPage
from lagou.appium_exercise4.pages.base_page import BasePage
from lagou.appium_exercise4.pages.member_info_page import MemberInfoPage


class AddressListPage(BasePage):
    addmember_ele = (MobileBy.XPATH, "//*[@text='添加成员']")
    name_list_ele = (MobileBy.XPATH,"//*[@class='android.widget.ListView']/android.widget.RelativeLayout")
    one_line_ele = (MobileBy.XPATH, "//*[@text='企业通讯录']/..//*[@class='android.widget.ImageView']")
    def add_member(self):
        # 点击添加成员
        self.swipe_find_and_click(*self.addmember_ele)
        return AddMemberPage(self.driver)

    def name_list_before(self):
        # 获取当前成员列表人数
        name_list = self.finds(*self.name_list_ele)
        name_list_before = len(name_list[2:-1])
        return name_list_before

    def click_one_member(self):
        # 点击第一行成员
        self.find_and_click(*self.one_line_ele)

        return MemberInfoPage(self.driver)

    def name_list_after(self):
        # 删除成员后，获取当前成员列表人数
        name_list = self.finds(*self.name_list_ele)
        name_list_after = len(name_list[2:-1])
        return name_list_after